package info.pinlab.pinplayer.model.response;

import info.pinlab.pinplayer.model.user.User;
import info.pinlab.util.HashCodeUtil;


public class ResponseToken extends ResponseInstance{
	private final String usr;
	private final String sessionId;
	
	public ResponseToken(ResponseInstance respi, String sessionId, User usr){
		super(respi);
		this.sessionId = sessionId;
		this.usr = usr.getId();
	}
	
	public String getSessionId(){
		return sessionId;
	}
	
	public String getUsrId(){
		return usr;
	}
	
	
	@Override
	public boolean equals(Object obj){
		if(!(obj instanceof ResponseToken))
			return false;
		ResponseToken other = (ResponseToken)obj;
		if(		super.equals(other)
			&& 	this.sessionId.equals(other.sessionId)
			&&	this.usr.equals(other.usr)
			){
			return true;
		}
		return false;
	}
	
	@Override
	public int hashCode(){
		int hash = 997;
		hash = HashCodeUtil.hash(hash, super.hashCode());
		hash = HashCodeUtil.hash(hash, usr);
		hash = HashCodeUtil.hash(hash, sessionId);
		return hash;
	}
	
	public static final String SEP = "_";
	public String getFileName(){
		return ""  
				+ sessionId + SEP 
				+ getTaskSetHash() + SEP 
				+ String.format("%02d", getTaskIx()) + SEP
				+ String.format("%02d", getAttemptN()) + SEP 
				+ getResponseContent().getClass().getSimpleName()
				;
	}
}
